<?php

class ProductSearchController
{
    private string $view = ROOT . '/views/admin/index.php';

    public function actionIndex(): bool
    {
        $data = $_POST;

        if (!empty($data['search'])) {
            echo json_encode(Product::findBiName($data['search']));
        } else {
            $result = [];
            foreach (Product::getList() as $product) {
                $result[] = ['id' => $product['id'], 'name' => $product['name']];
            }
            echo json_encode($result);
        }

        return true;
    }

}
